import React, { Component,PureComponent } from 'react';
import { Card, Image, List, Button, Modal } from 'antd-mobile';
import imgs from '../assets/images/d.jpg'
import { withRouter } from 'react-router-dom'
import req from '../http/req'
import url from '../config/url'
class Me extends PureComponent {
    state = {
        adminInfo: {
            last_login_addr: {}
        }
    }
    render() {
        return (
            <div>
                <Card style={{ margin: '10% 38% 3%' }}
                    title='我的信息'
                />
                <List style={{ fontSize: '16px', margin: '3% 8%' }}>
                    <List.Item
                        // style={{ fontSize: '24px', marginLeft: '6%' }}
                        prefix={
                            <Image
                                src={imgs}
                                style={{ borderRadius: 20 }}
                                fit='cover'
                                width={80}
                                height={80}
                            />}
                    >
                        {this.state.adminInfo.username}?{this.state.adminInfo.username} ( {this.state.adminInfo.role} ):''

                    </List.Item >
                    <List.Item >
                        上次登录:{this.state.adminInfo.last_login_addr.state}/{this.state.adminInfo.last_login_addr.isp}[{this.state.adminInfo.last_ip}]
                    </List.Item>
                    <List.Item >
                        账单
                    </List.Item>
                    <List.Item >
                        总资产
                    </List.Item>
                    <List.Item >
                        设置
                    </List.Item>

                    <List.Item onClick={this.props.history.replace('/login')}>
                        去登录
                    </List.Item>
                </List>
                <Button
                    color='primary'
                    size='middle'
                    style={{ margin: '3% 36%' }}
                    onClick={() =>
                        Modal.confirm({
                            content: '确认退出',
                            onConfirm: this.show
                        })
                    }
                >
                    退出登录
                </Button>
            </div >
        );
    }
    show = () => {
        localStorage.clear()
    }
    componentDidMount() {
        req.get(url.GettAdminInfo).then((res1) => {
            this.setState({
                adminInfo: {
                    username: res1.data.accountInfo.username,
                    role: res1.data.accountInfo.role,
                    last_login_addr: {
                        state: res1.data.accountInfo.last_login_addr.state,
                        isp: res1.data.accountInfo.last_login_addr.isp,
                    },
                    last_ip: res1.data.accountInfo.last_ip,
                }
            })
        })
    }



}

export default withRouter(Me);



